package com.parking.mgr.useraccount.facede;

import com.parking.mgr.useraccount.model.entity.UserInfoEntity;
import com.parking.mgr.useraccount.model.entity.UserPhoneEntity;
import com.parking.mgr.useraccount.service.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName ServiceFacede
 * @Description service 外观模式
 * @Auther: zhijianpu
 * @Date: 2023/6/12
 */
@Component
public class UserServiceFacede {

    @Resource
    private UserInfoService userInfoService;

    @Resource
    private LoginTokenService loginTokenService;

    @Resource
    private UserAccountService userAccountService;

    @Resource
    private UserPassportService userPassportService;

    @Resource
    private UserPhoneService userPhoneService;


    /**
     * 根据ID获取用户信息实体
     *
     * @param id
     * @return
     */
    public UserInfoEntity getUserInfoById(String id) {
        return userInfoService.getUserInfoById(id);
    }

    /**
     * 登录令牌获取用户账号
     *
     * @param request
     * @return
     */
    public String getPassportIdByToken(HttpServletRequest request) {
        return loginTokenService.getPassportIdByToken(request);
    }

    /**
     * 增加用户账户信息
     *
     * @param passportId
     * @param account
     */
    public void addUserAccount(String passportId, String account) {
        userAccountService.addUserAccount(passportId, account);
    }

    /**
     * 删除用户账户
     *
     * @param passportId
     */
    public void deleteAccountByPassportId(String passportId) {
        userAccountService.deleteAccountByPassportId(passportId);
    }


    /**
     * 增加用户账号
     *
     * @return
     */
    public String add() {
        return userPassportService.add();
    }

    /**
     * 根据用户账号删除手机号
     *
     * @param passportId
     */
    public void deleteUserPhoneByPassportId(String passportId) {
        userPhoneService.deleteUserPhoneByPassportId(passportId);
    }


    /**
     * 更新用户信息手机号
     *
     */
    public void updateUserPhone(UserPhoneEntity userPhoneEntity) {
        userInfoService.updateUserPhone(userPhoneEntity);
    }

    /**
     * 根据用户账号获取用户信息
     *
     * @param passportId
     * @return
     */
    public UserInfoEntity getUserInfoByPassportId(String passportId) {
        return userInfoService.getUserInfoByPassportId(passportId);
    }

    public void updateUserInfo(UserInfoEntity userInfoEntity) {
        userInfoService.updateById(userInfoEntity);
    }

    /**
     * 判断当前请求连接是是否是该用户角色的请求连接
     *
     * @param request
     * @return
     */
    public boolean isRoleUserMenu(HttpServletRequest request) {
        return userInfoService.isRoleUserMenu(request);
    }

}
